<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="登记日期" prop="zdrq">
        <el-date-picker clearable
          v-model="queryParams.zdrq"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择登记日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="车辆编码" prop="clbm">
        <el-input
          v-model="queryParams.clbm"
          placeholder="请输入车辆编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="司机姓名" prop="sjxm">
        <el-input
          v-model="queryParams.sjxm"
          placeholder="请输入司机姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆类型" prop="cllx">
        <el-input
          v-model="queryParams.cllx"
          placeholder="请输入车辆类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['basic/carinfo:cheliangda:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['basic/carinfo:cheliangda:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['basic/carinfo:cheliangda:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['basic/carinfo:cheliangda:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cheliangdaList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="jcCheliangdaoid" />
      <el-table-column label="登记日期" align="center" prop="zdrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zdrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆编码" align="center" prop="clbm" />
      <el-table-column label="司机姓名" align="center" prop="sjxm" />
      <el-table-column label="车辆类型" align="center" prop="cllx" />
      <el-table-column label="车辆分组" align="center" prop="clfz" />
      <el-table-column label="平均皮重" align="center" prop="pjpz" />
      <el-table-column label="上次皮重" align="center" prop="scpz" />
      <el-table-column label="累计车数" align="center" prop="ljcs" />
      <el-table-column label="备注" align="center" prop="bz" />
      <el-table-column label="单据类型" align="center" prop="djlx" />
      <el-table-column label="单据标识" align="center" prop="djbs" />
      <el-table-column label="单据状态" align="center" prop="djzt" />
      <el-table-column label="C01" align="center" prop="c01" />
      <el-table-column label="C02" align="center" prop="c02" />
      <el-table-column label="C03" align="center" prop="c03" />
      <el-table-column label="C04" align="center" prop="c04" />
      <el-table-column label="C05" align="center" prop="c05" />
      <el-table-column label="N01" align="center" prop="n01" />
      <el-table-column label="N02" align="center" prop="n02" />
      <el-table-column label="N03" align="center" prop="n03" />
      <el-table-column label="N04" align="center" prop="n04" />
      <el-table-column label="N05" align="center" prop="n05" />
      <el-table-column label="吨位" align="center" prop="dunwei" />
      <el-table-column label="轴数" align="center" prop="zhoushu" />
      <el-table-column label="车辆编号" align="center" prop="clbianhao" />
      <el-table-column label="车辆种类" align="center" prop="clzl" />
      <el-table-column label="车辆限重" align="center" prop="clxz" />
      <el-table-column label="道路运输证" align="center" prop="dlysz" />
      <el-table-column label="押运人员资质证" align="center" prop="yyryzzz" />
      <el-table-column label="从业资格证" align="center" prop="cyzgz" />
      <el-table-column label="危险货物种类" align="center" prop="wxhwzl" />
      <el-table-column label="行驶证质量" align="center" prop="xszzl" />
      <el-table-column label="大队编号" align="center" prop="daduibh" />
      <el-table-column label="小队编号" align="center" prop="xiaoduibh" />
      <el-table-column label="标准皮重" align="center" prop="bzpz" />
      <el-table-column label="黑名单标识" align="center" prop="hmdbs" />
      <el-table-column label="黑名单终止日期" align="center" prop="hmdzzrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.hmdzzrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否永久" align="center" prop="sfyj" />
      <el-table-column label="黑名单标志" align="center" prop="hmdbz" />
      <el-table-column label="驱动桥" align="center" prop="qdq" />
      <el-table-column label="承运单位OID" align="center" prop="jcKeshangdaoid" />
      <el-table-column label="审核人OID" align="center" prop="shroid" />
      <el-table-column label="超重控制OID" align="center" prop="jcCzkzoid" />
      <el-table-column label="司机姓名2" align="center" prop="sjxm2" />
      <el-table-column label="核定载重" align="center" prop="hdzz" />
      <el-table-column label="驾驶证" align="center" prop="jsz" />
      <el-table-column label="车辆识别代号" align="center" prop="clsbdh" />
      <el-table-column label="注册日期" align="center" prop="zcrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zcrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="排放阶段" align="center" prop="pfjd" />
      <el-table-column label="GPS接口OID" align="center" prop="jkGpsinfooid" />
      <el-table-column label="车辆GPS平台ID" align="center" prop="gpsclid" />
      <el-table-column label="GPS到期时间" align="center" prop="gpsexpiredate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gpsexpiredate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆Acc状态" align="center" prop="isacc" />
      <el-table-column label="定位时间" align="center" prop="gpstime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gpstime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆状态" align="center" prop="vehiclestatus" />
      <el-table-column label="GPS创建时间" align="center" prop="createtime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车组ID" align="center" prop="groupid" />
      <el-table-column label="GPS终端号" align="center" prop="gpszdh" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['basic/carinfo:cheliangda:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['basic/carinfo:cheliangda:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改车辆档案对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="主键" prop="jcCheliangdaoid">
          <el-input v-model="form.jcCheliangdaoid" placeholder="请输入主键" />
        </el-form-item>
        <el-form-item label="登记日期" prop="zdrq">
          <el-date-picker clearable
            v-model="form.zdrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择登记日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="车辆编码" prop="clbm">
          <el-input v-model="form.clbm" placeholder="请输入车辆编码" />
        </el-form-item>
        <el-form-item label="司机姓名" prop="sjxm">
          <el-input v-model="form.sjxm" placeholder="请输入司机姓名" />
        </el-form-item>
        <el-form-item label="车辆类型" prop="cllx">
          <el-input v-model="form.cllx" placeholder="请输入车辆类型" />
        </el-form-item>
        <el-form-item label="车辆分组" prop="clfz">
          <el-input v-model="form.clfz" placeholder="请输入车辆分组" />
        </el-form-item>
        <el-form-item label="平均皮重" prop="pjpz">
          <el-input v-model="form.pjpz" placeholder="请输入平均皮重" />
        </el-form-item>
        <el-form-item label="上次皮重" prop="scpz">
          <el-input v-model="form.scpz" placeholder="请输入上次皮重" />
        </el-form-item>
        <el-form-item label="累计车数" prop="ljcs">
          <el-input v-model="form.ljcs" placeholder="请输入累计车数" />
        </el-form-item>
        <el-form-item label="备注" prop="bz">
          <el-input v-model="form.bz" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="单据类型" prop="djlx">
          <el-input v-model="form.djlx" placeholder="请输入单据类型" />
        </el-form-item>
        <el-form-item label="单据标识" prop="djbs">
          <el-input v-model="form.djbs" placeholder="请输入单据标识" />
        </el-form-item>
        <el-form-item label="单据状态" prop="djzt">
          <el-input v-model="form.djzt" placeholder="请输入单据状态" />
        </el-form-item>
        <el-form-item label="C01" prop="c01">
          <el-input v-model="form.c01" placeholder="请输入C01" />
        </el-form-item>
        <el-form-item label="C02" prop="c02">
          <el-input v-model="form.c02" placeholder="请输入C02" />
        </el-form-item>
        <el-form-item label="C03" prop="c03">
          <el-input v-model="form.c03" placeholder="请输入C03" />
        </el-form-item>
        <el-form-item label="C04" prop="c04">
          <el-input v-model="form.c04" placeholder="请输入C04" />
        </el-form-item>
        <el-form-item label="C05" prop="c05">
          <el-input v-model="form.c05" placeholder="请输入C05" />
        </el-form-item>
        <el-form-item label="N01" prop="n01">
          <el-input v-model="form.n01" placeholder="请输入N01" />
        </el-form-item>
        <el-form-item label="N02" prop="n02">
          <el-input v-model="form.n02" placeholder="请输入N02" />
        </el-form-item>
        <el-form-item label="N03" prop="n03">
          <el-input v-model="form.n03" placeholder="请输入N03" />
        </el-form-item>
        <el-form-item label="N04" prop="n04">
          <el-input v-model="form.n04" placeholder="请输入N04" />
        </el-form-item>
        <el-form-item label="N05" prop="n05">
          <el-input v-model="form.n05" placeholder="请输入N05" />
        </el-form-item>
        <el-form-item label="吨位" prop="dunwei">
          <el-input v-model="form.dunwei" placeholder="请输入吨位" />
        </el-form-item>
        <el-form-item label="轴数" prop="zhoushu">
          <el-input v-model="form.zhoushu" placeholder="请输入轴数" />
        </el-form-item>
        <el-form-item label="车辆编号" prop="clbianhao">
          <el-input v-model="form.clbianhao" placeholder="请输入车辆编号" />
        </el-form-item>
        <el-form-item label="车辆种类" prop="clzl">
          <el-input v-model="form.clzl" placeholder="请输入车辆种类" />
        </el-form-item>
        <el-form-item label="车辆限重" prop="clxz">
          <el-input v-model="form.clxz" placeholder="请输入车辆限重" />
        </el-form-item>
        <el-form-item label="道路运输证" prop="dlysz">
          <el-input v-model="form.dlysz" placeholder="请输入道路运输证" />
        </el-form-item>
        <el-form-item label="押运人员资质证" prop="yyryzzz">
          <el-input v-model="form.yyryzzz" placeholder="请输入押运人员资质证" />
        </el-form-item>
        <el-form-item label="从业资格证" prop="cyzgz">
          <el-input v-model="form.cyzgz" placeholder="请输入从业资格证" />
        </el-form-item>
        <el-form-item label="危险货物种类" prop="wxhwzl">
          <el-input v-model="form.wxhwzl" placeholder="请输入危险货物种类" />
        </el-form-item>
        <el-form-item label="行驶证质量" prop="xszzl">
          <el-input v-model="form.xszzl" placeholder="请输入行驶证质量" />
        </el-form-item>
        <el-form-item label="大队编号" prop="daduibh">
          <el-input v-model="form.daduibh" placeholder="请输入大队编号" />
        </el-form-item>
        <el-form-item label="小队编号" prop="xiaoduibh">
          <el-input v-model="form.xiaoduibh" placeholder="请输入小队编号" />
        </el-form-item>
        <el-form-item label="标准皮重" prop="bzpz">
          <el-input v-model="form.bzpz" placeholder="请输入标准皮重" />
        </el-form-item>
        <el-form-item label="黑名单标识" prop="hmdbs">
          <el-input v-model="form.hmdbs" placeholder="请输入黑名单标识" />
        </el-form-item>
        <el-form-item label="黑名单终止日期" prop="hmdzzrq">
          <el-date-picker clearable
            v-model="form.hmdzzrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择黑名单终止日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否永久" prop="sfyj">
          <el-input v-model="form.sfyj" placeholder="请输入是否永久" />
        </el-form-item>
        <el-form-item label="黑名单标志" prop="hmdbz">
          <el-input v-model="form.hmdbz" placeholder="请输入黑名单标志" />
        </el-form-item>
        <el-form-item label="驱动桥" prop="qdq">
          <el-input v-model="form.qdq" placeholder="请输入驱动桥" />
        </el-form-item>
        <el-form-item label="承运单位OID" prop="jcKeshangdaoid">
          <el-input v-model="form.jcKeshangdaoid" placeholder="请输入承运单位OID" />
        </el-form-item>
        <el-form-item label="审核人OID" prop="shroid">
          <el-input v-model="form.shroid" placeholder="请输入审核人OID" />
        </el-form-item>
        <el-form-item label="超重控制OID" prop="jcCzkzoid">
          <el-input v-model="form.jcCzkzoid" placeholder="请输入超重控制OID" />
        </el-form-item>
        <el-form-item label="司机姓名2" prop="sjxm2">
          <el-input v-model="form.sjxm2" placeholder="请输入司机姓名2" />
        </el-form-item>
        <el-form-item label="核定载重" prop="hdzz">
          <el-input v-model="form.hdzz" placeholder="请输入核定载重" />
        </el-form-item>
        <el-form-item label="驾驶证" prop="jsz">
          <el-input v-model="form.jsz" placeholder="请输入驾驶证" />
        </el-form-item>
        <el-form-item label="车辆识别代号" prop="clsbdh">
          <el-input v-model="form.clsbdh" placeholder="请输入车辆识别代号" />
        </el-form-item>
        <el-form-item label="注册日期" prop="zcrq">
          <el-date-picker clearable
            v-model="form.zcrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择注册日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="排放阶段" prop="pfjd">
          <el-input v-model="form.pfjd" placeholder="请输入排放阶段" />
        </el-form-item>
        <el-form-item label="GPS接口OID" prop="jkGpsinfooid">
          <el-input v-model="form.jkGpsinfooid" placeholder="请输入GPS接口OID" />
        </el-form-item>
        <el-form-item label="车辆GPS平台ID" prop="gpsclid">
          <el-input v-model="form.gpsclid" placeholder="请输入车辆GPS平台ID" />
        </el-form-item>
        <el-form-item label="GPS到期时间" prop="gpsexpiredate">
          <el-date-picker clearable
            v-model="form.gpsexpiredate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择GPS到期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="车辆Acc状态" prop="isacc">
          <el-input v-model="form.isacc" placeholder="请输入车辆Acc状态" />
        </el-form-item>
        <el-form-item label="定位时间" prop="gpstime">
          <el-date-picker clearable
            v-model="form.gpstime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择定位时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="车组ID" prop="groupid">
          <el-input v-model="form.groupid" placeholder="请输入车组ID" />
        </el-form-item>
        <el-form-item label="GPS终端号" prop="gpszdh">
          <el-input v-model="form.gpszdh" placeholder="请输入GPS终端号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCheliangda, getCheliangda, delCheliangda, addCheliangda, updateCheliangda } from "@/api/basic/carinfo/cheliangda";

export default {
  name: "Cheliangda",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆档案表格数据
      cheliangdaList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zdrq: null,
        clbm: null,
        sjxm: null,
        cllx: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        jcCheliangdaoid: [
          { required: true, message: "主键不能为空", trigger: "blur" }
        ],
        zdrq: [
          { required: true, message: "登记日期不能为空", trigger: "blur" }
        ],
        clbm: [
          { required: true, message: "车辆编码不能为空", trigger: "blur" }
        ],
        sjxm: [
          { required: true, message: "司机姓名不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询车辆档案列表 */
    getList() {
      this.loading = true;
      listCheliangda(this.queryParams).then(response => {
        this.cheliangdaList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        jcCheliangdaoid: null,
        zdrq: null,
        clbm: null,
        sjxm: null,
        cllx: null,
        clfz: null,
        pjpz: null,
        scpz: null,
        ljcs: null,
        bz: null,
        djlx: null,
        djbs: null,
        djzt: null,
        c01: null,
        c02: null,
        c03: null,
        c04: null,
        c05: null,
        n01: null,
        n02: null,
        n03: null,
        n04: null,
        n05: null,
        dunwei: null,
        zhoushu: null,
        clbianhao: null,
        clzl: null,
        clxz: null,
        dlysz: null,
        yyryzzz: null,
        cyzgz: null,
        wxhwzl: null,
        xszzl: null,
        daduibh: null,
        xiaoduibh: null,
        bzpz: null,
        hmdbs: null,
        hmdzzrq: null,
        sfyj: null,
        hmdbz: null,
        qdq: null,
        jcKeshangdaoid: null,
        shroid: null,
        jcCzkzoid: null,
        sjxm2: null,
        hdzz: null,
        jsz: null,
        clsbdh: null,
        zcrq: null,
        pfjd: null,
        jkGpsinfooid: null,
        gpsclid: null,
        gpsexpiredate: null,
        isacc: null,
        gpstime: null,
        vehiclestatus: null,
        createtime: null,
        groupid: null,
        gpszdh: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.jcCheliangdaoid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加车辆档案";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const jcCheliangdaoid = row.jcCheliangdaoid || this.ids
      getCheliangda(jcCheliangdaoid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改车辆档案";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.jcCheliangdaoid != null) {
            updateCheliangda(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCheliangda(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const jcCheliangdaoids = row.jcCheliangdaoid || this.ids;
      this.$modal.confirm('是否确认删除车辆档案编号为"' + jcCheliangdaoids + '"的数据项？').then(function() {
        return delCheliangda(jcCheliangdaoids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('basic/carinfo/cheliangda/export', {
        ...this.queryParams
      }, `cheliangda_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
